home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / linkedit / linkedit.lha / link-edit / LinkEdit / Box / box_kp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-13  |  2.4 KB  |  117 lines

  1. #include <stdio.h>
  2. #include <X11/Xlib.h>
  3. #include "box_types.h"
  4. #include "box_global.h"
  5.  
  6. BoxKeyPressEvent(gnrc,event)
  7.  
  8. BoxStatus *gnrc;
  9. XEvent *event;
  10.  
  11. {
  12.   char key,strng[2];
  13.  
  14.   if(XLookupString(&(event->xkey),strng,1,NULL,NULL) == 0) {
  15.      BoxPrintMessage(gnrc,"Can't handle that key!");
  16.      return(-1);
  17.     }
  18.   key = strng[0];
  19.   BoxKeyPress(gnrc,key);
  20. }
  21.  
  22. BoxKeyPress(gnrc,key)
  23.  
  24. BoxStatus *gnrc;
  25. char key;
  26.  
  27. {
  28.   BoxList *bx;
  29.  
  30.   if(gnrc->current_box->type == BOX_TEXT_ENTRY) {
  31.      BoxTextEntryKey(gnrc,gnrc->current_box,key);
  32.      /* Do continuous callbacks */
  33.      bx = gnrc->current_box;
  34.      if(bx->continuous_local_callback != NULL) 
  35.            (*(bx->continuous_local_callback))(gnrc,bx);
  36.      if(bx->continuous_global_callback != NULL) 
  37.            (*(bx->global_callback))(gnrc->arg,(VOID *)gnrc,bx->id);
  38.      return(0);
  39.     }
  40.  
  41.   /* else check if keypress matches any valid box keycode */
  42.  
  43.   bx = gnrc->box.next;
  44.   while(bx != NULL) {
  45.      if(bx->key == key) {
  46.         if(BoxIsValidChoice(gnrc,bx)) break;
  47.        }
  48.      bx = bx->next;
  49.     }
  50.  
  51.   if(bx == NULL) {
  52.      BoxPrintMessage(gnrc,"No valid choice with that keycode.");
  53.      return(0);
  54.     }
  55.    if(bx->visible == BOX_NO && bx->always_visible == BOX_NO) {
  56.      /* Can`t select with key an invisible box! */
  57.      BoxPrintMessage(gnrc,"No valid choice with that keycode.");
  58.      return(0);
  59.     }
  60.   BoxSelect(gnrc,bx);
  61. }
  62.  
  63. BoxTextEntryKey(gnrc,bx,key)
  64.  
  65. BoxStatus *gnrc;
  66. BoxList *bx;
  67. char key;
  68.  
  69. {
  70.  
  71.   int pstn;
  72.   char *strng;
  73.   BoxList *child;
  74.  
  75.   if(bx->type != BOX_TEXT_ENTRY || bx->state != BOX_YES) return(0);
  76.  
  77.   strng = bx->dflt.text;
  78.   pstn = strlen(strng);
  79.  
  80.   if((key >= 32) && (key <= 126)) {
  81.      strng[pstn] = key; strng[pstn+1] = '\0';
  82.      DrawBox(gnrc,bx);
  83.     }
  84.  
  85.   if((key == 8) || (key == 127)) {
  86.      if(pstn > 0) {
  87.         strng[pstn-1] = '\0';
  88.         DrawBox(gnrc,bx);
  89.        }
  90.     }
  91.  
  92.   if(key == '\r') {
  93.  
  94.      /* Do callbacks */
  95.      if(bx->local_callback != NULL) {
  96.         (*(bx->local_callback))(gnrc,bx);
  97.        }
  98.      if(bx->global_callback != NULL) {
  99.         (*(bx->global_callback))(gnrc->arg,(VOID *)gnrc,bx->id);
  100.        }
  101.  
  102.      /* draw children */
  103.       child = bx->child;
  104.       while(child != NULL) {
  105.          child->visible = BOX_YES; DrawBox(gnrc,child);
  106.          child = child->sibling;
  107.         }
  108.  
  109.       if(bx->induce_state_change == BOX_YES) {
  110.          gnrc->state_change = BOX_YES;
  111.          gnrc->select_box = bx;
  112.         }
  113.       if(bx->cleanup == BOX_YES)  BoxCleanup(gnrc,bx);
  114.     }
  115. }
  116.  
  117.